package com.zhangye.test.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import com.zhangye.test.mapper.RegionMapper;
import com.zhangye.test.model.Region;
import com.zhangye.test.util.PageInfo;

/**
 * 举报
 * 作者： 张叶
 * 创建时间：2018年8月29日  上午9:31:04
 */
@Service
public class RegionService {

	@Autowired
	private RegionMapper regionMapper;
	
	public List<Region> selectByWhere(String where){
		List<Region> list = regionMapper.selectByWhere(where);
		return list;
	}
	
	public int insert(Region r){
		int i = regionMapper.insert(r);
		return i;
	}


	/**
	 * 列表
	 * 作者： 张叶
	 * 创建时间：2018年8月29日  下午4:41:36
	 */
	public List<Map<String,Object>> selectByPage(PageInfo pageInfo, String where, String order) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("myCount", pageInfo.getCount());
		param.put("pageSize", pageInfo.getPageSize());
		param.put("page", pageInfo.getPage());
		param.put("where", where);
		param.put("order", order); 
		List<Map<String, Object>> m = regionMapper.selectByPage(param);
		pageInfo.setCount(Integer.parseInt(param.get("myCount").toString()));
		return m;
	}
	
	
	public Region getRegionByCode(String code){
		String where = " and code = '" + code + "'";
		List<Region> list = regionMapper.selectByWhere(where);
		if(list.size() > 0){
			return list.get(0);
		}else{
			return null;
		}
	}
	
}
